<%@page import="com.glowdayz.common.DateTime"%>
<%@page import="com.glowdayz.glowmee.dao.CommonCodeDAO"%>
<%@page import="com.glowdayz.glowmee.cmd.CommonCodeCMD"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.glowdayz.common.PageHandler"%>
<%@page import="com.glowdayz.common.ApiHandler"%>
<%@page import="com.glowdayz.common.DBHandler"%>
<%@ page language="java" contentType="text/xml; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%
	DBHandler.getInstance().connect();
	
	ApiHandler web = new ApiHandler(request, out, "JSPglowmee");
	
	String parentId = web.getValue("parentId");
	String order = web.getValue("order");
	String sido = web.getValue("sido");
	
	int total_count = 0;
	if (sido != null && !sido.equals("")) {
		total_count = DBHandler.getInstance().getCount("commoncode", "*", "parentId = (SELECT idCommon FROM CommonCode WHERE commonText='" + sido + "')");
	} else {
		total_count = DBHandler.getInstance().getCount("commoncode", "*", "parentId = (SELECT idCommon FROM commoncode WHERE commonText='" + parentId + "')");
	}
	
	PageHandler p = PageHandler.getInstance(1, total_count);
	
	ArrayList<CommonCodeCMD> list = null;
	
	if (sido != null && !sido.equals("")) {
		list = CommonCodeDAO.getInstance().getCommonCodeList("idCommon", "parentId = (SELECT idCommon FROM CommonCode WHERE commonText='" + sido + "')");
	} else if (order.equals("desc")) {
		list = CommonCodeDAO.getInstance().getCommonCodeList("commonText DESC", "parentId = (SELECT idCommon FROM commoncode WHERE commonText='" + parentId + "')");
	} else {
		list = CommonCodeDAO.getInstance().getCommonCodeList("idCommon", "parentId = (SELECT idCommon FROM commoncode WHERE commonText='" + parentId + "')");
	}
	
	if (list == null) {
		DBHandler.getInstance().disconnect();
		web.result(null, "데이터 조회에 실패했습니다. 잠시후 다시 시도해 주세요.");
		return;
	}
	DBHandler.getInstance().disconnect();
%>
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
	<channel>
		<!-- ##### 이 데이터를 소개하는 부분 (필수항목들) ##### -->
		<!-- 제목 -->
		<title>글로우미</title>
		<!-- XML 생성일시 -->
		<pubDate><%=DateTime.getInstance().getNowDateTimeString()%></pubDate>
		
		<!-- ##### 추가적인 정보들 (일반적으로 페이징 처리에 관련된 변수들) ##### -->
		<totalArticleCount><%=p.getTotalArticleCount()%></totalArticleCount>
		
		<!-- ##### 게시물 정보 반복 처리 ##### -->
		<!-- 추가적인 정보를 덧붙이거나, 필요 없는 정보는 삭제 가능함 -->
		<%
			if (list != null) {
				for (int i=0; i<list.size(); i++) {
					CommonCodeCMD item = list.get(i);
		%>
		<item>
			<!-- 항번 -->
			<idCommon><![CDATA[<%=item.getIdCommon()%>]]></idCommon>
			<!-- 부모 항번 -->
			<parentId><![CDATA[<%=item.getParentId()%>]]></parentId>
			<!-- 내용 -->
			<commonText><![CDATA[<%=item.getCommonText()%>]]></commonText>
			<!-- 순서 -->
			<sortKey><![CDATA[<%=item.getSortKey()%>]]></sortKey>
			<!-- 전시여부 -->
			<isDisplay><![CDATA[<%=item.getIsDisplay()%>]]></isDisplay>
			<!-- 작성일자 -->
			<create_date><![CDATA[<%=item.getCreate_date()%>]]></create_date>
			<!-- 수정일자 -->
			<modified_date><![CDATA[<%=item.getModified_date()%>]]></modified_date>
		</item>
		<%
				}
			}
		%>
	</channel>
</rss>